package com.springboot.reidssort.controller;

import com.springboot.reidssort.service.ChapterService;
import com.springboot.reidssort.util.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@Controller
@RequestMapping("/api/chapter")
public class ChapterController {

    @Autowired
    private ChapterService chapterService;


    /**
     * 进入管理页面
     * @return
     */
    @RequestMapping("/index")
    public String index(Model model){
        chapterService.addToSortedSet();
        List<Test> people = chapterService.getSortedSet();
        model.addAttribute("people", people);
        return "list";
    }


    // 添加元素到有序列表
    @PostMapping("/add")
    @ResponseBody
    public String add() {
        chapterService.addToSortedSet();
        return "Added successfully!";
    }

    // 获取有序列表的所有元素
    @GetMapping("/list")
    @ResponseBody
    public List<Test> list() {
        return chapterService.getSortedSet();
    }



}
